/*
 * @lc app=leetcode.cn id=318 lang=csharp
 *
 * [318] 最大单词长度乘积
 */

// @lc code=start
public class Solution {
    public int MaxProduct(string[] words) {
        int[] masks = new int[words.Length];
        for (int i = 0; i < words.Length; i++)
        {
            foreach (var c in words[i])
            {
                masks[i] |= 1 << (c - 'a'); // 存在的字母， 对应位标记为1
            }
        }
        int max = 0;
        for (int i = 0; i < masks.Length; i++)
        {
            for (int j = i + 1; j < masks.Length; j++)
            {
                if ((masks[i] & masks[j]) == 0) // 两个单词没有相同字母
                {
                    max = Math.Max(max, words[i].Length * words[j].Length);
                }
            }
        }
        return max;
    }
}
// @lc code=end

